﻿using System.Collections.Generic;
using Abp.Configuration;
using Microsoft.Extensions.Configuration;
using pandx.Mulan.Configuration;

namespace pandx.Mulan.Settings
{
    public class AppSettingProvider : SettingProvider
    {
        private readonly IConfigurationRoot _configuration;

        public AppSettingProvider(IAppConfigurationAccessor configurationAccessor)
        {
            _configuration = configurationAccessor.Configuration;
        }
        
        public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
        {
           
            return new[]
            {
                new SettingDefinition(AppSettings.Email.UseHostDefaultEmail,CoreConsts.MultiTenancyEnabled?"true":"false",scopes:SettingScopes.Tenant),
                new SettingDefinition(AppSettings.PeriodicBackgroundWorker.ExpireAuditLogDelete,"10",scopes:SettingScopes.Application),
                new SettingDefinition(AppSettings.Security.AllowOneConcurrentLoginPerUser,"True",scopes:SettingScopes.Application),
                
            };
        }

        private string GetFromAppSettings(string name, string defaultValue = null)
        {
            return GetFromSettings("App:" + name, defaultValue);
        }

        private string GetFromSettings(string name, string defaultValue = null)
        {
            return _configuration[name] ?? defaultValue;
        }
    }
}

